/**
 * 直接 pnpm install color-thief 会报错
 * 没有声明文件需要自己生成 colorthief.d.ts
 * if you pnpm install color-thief,you will report an error with node-gyp
 * this is an issues of color-thief on github https://github.com/lokesh/color-thief/issues/217
 * you can use pnpm install colorthief@npm:@pioug/colorthief instead
 */

import ColorThief from 'colorthief'

export const useColorThief = () => {
  const colorThief = new ColorThief()
  /**获取图片主要颜色 */
  const getColor = async (sourceImage: HTMLImageElement, quality?: number): Promise<number[]> => {
    return await colorThief.getColor(sourceImage, quality)
  }

  /**获取前几种颜色 */
  const getPalette = async (
    sourceImage: HTMLImageElement,
    colorCount?: number,
    quality?: number
  ): Promise<number[][]> => {
    return await colorThief.getPalette(sourceImage, colorCount, quality)
  }

  /**给某一个 */
  const setColor = () => {}

  return {
    getColor,
    getPalette,
  }
}
